// pages/index/index.js
var WxParse = require('../../lib/wxParse/wxParse.js');
var WxParse = require('../../lib/wxParse/wxParse.js');
Page({
  data:{
    categoryId:1,
    detail: '',
    isFull:false   //用户数据是否完整
  },
   //分享功能
   onShareAppMessage:function(){
    return {
      title: '油菜花',
      desc: '油菜花',
      path: '/page/majar/majarlist'
    }
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    this.loadMajorDetail({ majorId: options.majorid, universityId:options.schoolid});    
  },
  
  onReady:function(){
    // 页面渲染完成
   
  },
  onShow:function(){
    // 页面显示
    if (typeof (this.data.userDataSave) != "undefined" && this.data.userDataSave == true){
      wx.showToast({
        title: "报名成功",
        icon: 'success',
        duration: 1000,
        mask: true
      })
      this.setData({userDataSave:false});
     
    }
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  openMajorSchoolListWindow: function (e){
    
    wx.navigateTo({
      url: './majar_school_list?majarid=' + e.currentTarget.dataset.majarid,
    })
    //TODO 在这里加载数据
    
  },
  loadMajorDetail:function(requestObj){
    var self = this;
    wx.request({
      url: getApp().globalData.server + "/university/university_major_detail.do",
      data: requestObj,
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        if (res.data.status != 0) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 1000,
            mask: true
          })
        } else {
          console.log(requestObj);
          console.log(res.data);
          var detail = res.data.data.list[0].introduce.detail;
          WxParse.wxParse('majar_detail', 'html', detail, self, 5);
          //wx.setNavigationBarTitle({
            //title: res.data.data.list[0].majors.name,
          //})
          self.setData({
            majorSchoolDetail: res.data.data.list[0],
          });

        }

      },
      fail: function () {
        wx.showToast({
          title: "获取专业详情失败",
          icon: 'none',
          duration: 1000,
          mask: true
        })
      }
    })

  },
  enroll:function(e){
    /*
    wx.navigateTo({
      url: '/page/my/enroll_detail?enrollId=0' 
       
    })*/
    var self = this;
    getApp().login(function () {
      if (self.data.isFull || getApp().globalData.hasLogin) {
        wx.showToast({
          title: "报名成功",
          icon: 'success',
          duration: 2000,
          mask: true
        })
        //TODO 报名信息持久化
      }
      else{
        wx.navigateTo({
          url: '/page/my/account'
        })
      }
      
    });
    
  }
})